package com.bwie.task;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Author GaoYiJie
 * @Description
 * @Create 2025/4/17 10:30
 * @Version 1.0
 */
@Component
@Slf4j
public class GenerateTokenTask {

    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Scheduled(cron = "0 0/5 * * * ?")//正确
    //@Scheduled(cron = "0 0/1 * * * ?")//测试
    public void generateTokenTask(){

        log.info("开始生成token");

        //国家系统生成token
        String token = Jwts.builder().signWith(SignatureAlgorithm.HS256, "123456").compact();

        //存入缓存,刷新token
        String nationTokenKey = "nation_token";
        stringRedisTemplate.opsForValue().set(nationTokenKey,token,5, TimeUnit.MINUTES);
        log.info("token刷新结束");
    }
}
